#include "Transaction.hh"
#include <ctime>

int Transaction::nextTransactionID = 1;

Transaction::Transaction() : amount(0.0), type(""), note("") {
    transactionID = nextTransactionID++;
    timestamp = time(nullptr);
}
Transaction::Transaction(double amount, const std::string& type, const std::string& note)
    : amount(amount), type(type), note(note), timestamp(time(nullptr)) {
    transactionID = nextTransactionID++;
}
Transaction::~Transaction() {
}
Transaction::Transaction(const Transaction& other) {
    transactionID = other.transactionID;
    amount = other.amount;
    type = other.type;
    note = other.note;
    timestamp = other.timestamp;
}
Transaction& Transaction::operator=(const Transaction& other) {
    if (this != &other) {
        transactionID = other.transactionID;
        amount = other.amount;
        type = other.type;
        note = other.note;
        timestamp = other.timestamp;
    }
    return *this;
}


int Transaction::getTransactionID() const {
    return transactionID;
}

double Transaction::getAmount() const {
    return amount;
}

const std::string& Transaction::getType() const {
    return type;
}

const std::string& Transaction::getNote() const {
    return note;
}

time_t Transaction::getTimestamp() const {
    return timestamp;
}

void Transaction::resetNextTransactionID() {
    nextTransactionID = 1;
}

void Transaction::print() const {
    std::cout << "---------------------------------\n";
    std::cout << "Transaction ID: " << transactionID << "\n";
    std::cout << "Type: " << type << "\n";
    std::cout << "Amount: $" << std::fixed << std::setprecision(2) << amount << "\n";
    std::cout << "Note: " << note << "\n";
    std::cout << "Timestamp: " << std::asctime(std::localtime(&timestamp)) << "\n";
    std::cout << "---------------------------------\n";
}